home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / dissolve.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  121 lines

  1. ; $Id: dissolve.pro,v 1.3 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1990-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6.  
  7. pro DISSOLVE, image, SIZ = siz, X0 = x0, Y0 = y0, DELAY = delay, $
  8.     ORDER = order
  9. ;+
  10. ; NAME:
  11. ;    DISSOLVE
  12. ;
  13. ; PURPOSE:
  14. ;    A digital "dissolve" effect for images.  Copies the pixels (arranged
  15. ;    into square tiles) from the image to the display in pseudo-random
  16. ;    order.
  17. ;
  18. ; CATEGORY:
  19. ;    Image display.
  20. ;
  21. ; CALLING SEQUENCE:
  22. ;    DISSOLVE, Image
  23. ;
  24. ; INPUTS:
  25. ;    Image:    The image to be displayed.  It is assumed that the image is
  26. ;        already scaled.  Byte-valued images display most rapidly.
  27. ;
  28. ; OPTIONAL INPUT PARAMETERS:
  29. ;    None.
  30. ;
  31. ; KEYWORD PARAMETERS:
  32. ;    SIZ:    Size of square tile.  The default is 32 x 32 pixels.
  33. ;
  34. ;    X0, Y0: The X and Y offsets of the lower-left corner of the image on 
  35. ;        screen.  The defaults are X0 = 0 and Y0 = 0.
  36. ;
  37. ;    DELAY:    The wait between displaying tiles.  The default is 0.01 secs.
  38. ;
  39. ;    ORDER:    The Image display order:      0 = default = bottom up.
  40. ;                        1 = top-down.
  41. ;
  42. ; OUTPUTS:
  43. ;    No explicit outputs.
  44. ;
  45. ; COMMON BLOCKS:
  46. ;    None.
  47. ;
  48. ; SIDE EFFECTS:
  49. ;    The image is written to the screen.
  50. ;
  51. ; RESTRICTIONS:
  52. ;    None, but the effect is dependent upon the speed of the
  53. ;    machine/display.
  54. ;
  55. ; PROCEDURE:
  56. ;    An integer pseudo-random number generator is used to decide
  57. ;    which tile to display.  The algorithm is taken from "Graphics Gems",
  58. ;    Andrew Glassner, ed., Academic Press, 1990, Page 221.
  59. ;
  60. ; MODIFICATION HISTORY:
  61. ;    DMS, Sept, 1990.
  62. ;-
  63.  
  64. ; Do a random dissolve, using the TV command.
  65. if n_elements(siz) le 0 then siz = 32    ;Default square size....
  66. if n_elements(x0) le 0 then x0 = 0
  67. if n_elements(y0) le 0 then y0 = 0
  68. if n_elements(delay) le 0 then delay = 0.01
  69. if n_elements(order) le 0 then order = 0
  70.  
  71. s = size(image)
  72. nx = s[1]
  73. ny = s[2]
  74. siz = siz < nx < ny        ;Never smaller than dims
  75.  
  76. nxs = (nx + siz - 1) / siz    ;Squares across
  77. nys = (ny + siz - 1) / siz    ;Squares up/down
  78.  
  79.  
  80. rwidth = alog(nys)/alog(2)    ;Bits/dimension
  81. cwidth = alog(nxs)/alog(2)
  82. if rwidth ne fix(rwidth) then rwidth = rwidth + 1  ;Ceiling fcn
  83. if cwidth ne fix(cwidth) then cwidth = cwidth + 1 
  84. rwidth = fix(rwidth)
  85. cwidth = fix(cwidth)
  86. regwidth = rwidth + cwidth    ;Total width
  87.  
  88. ; The shift reg mask
  89. mask = ([ '3'xl, '6'xl, '0c'xl,'14'xl, '30'xl, '60'xl, 'b8'xl, '0110'xl, $
  90.     '240'xl, '500'xl, '0ca0'xl, '01b00'xl, '3500'xl, $
  91.     '6000'xl, 'b400'xl, '12000'xl, '20400'xl, '72000'xl, $
  92.     '90000'xl, '140000'xl, '300000'xl, '400000'xl ])[regwidth-2]
  93.  
  94. colmask = ishft(1,cwidth) -1    ;Mask to extract column
  95.  
  96. start_seq = long(systime(1) mod ishft(1,regwidth-1)) ;Random starting cell
  97. if start_seq le 0 then start_seq = 1L
  98. seq = start_seq
  99. repeat begin
  100.     row = ishft(seq, -cwidth)    ;The row chunk
  101.     col = seq and colmask        ;Col chunk
  102.     if (row lt nys) and (col  lt nxs) then begin  ;Within image?
  103.         y00 = row * siz
  104.         x00 = col * siz
  105.         y01 = (y00 + siz-1) < (ny-1)
  106.         x01 = (x00 + siz-1) < (nx-1)
  107.         if order ne 0 then $
  108.           y02 = ny - y00 - (y01-y00) > 0 else y02 = y00
  109.         tv,image[x00:x01, y00:y01], x00 + x0, y02+y0, order = order
  110.         wait,delay
  111.         endif
  112.     if seq and 1 then seq = ishft(seq, -1) xor mask $
  113.     else seq = ishft(seq, -1)
  114. endrep until seq eq start_seq
  115.  
  116. if order eq 0 then tv,image[0:siz-1, 0:siz-1],x0,y0 $    ;Last chunk
  117. else tv,image[0:siz-1, 0:siz-1],x0, y0 + ny-siz, /order
  118. empty
  119. end
  120.